#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
vector<int> cards[14];
int cnt[14];

int f(char c) {
  if (isdigit(c)) {
    int d = c - '0';
    if (d == 0) d = 10;
    return d;
  } else if (c == 'A')
    return 1;
  else if (c == 'J')
    return 11;
  else if (c == 'Q')
    return 12;
  else
    return 13;
}
int main() {
  // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  rep(i, 1, 13) {
    char c;
    rep(j, 0, 3) {
      cin >> c;
      cards[i].push_back(f(c));
    }
  }
  reverse(cards[13].begin(), cards[13].end());
  int p = 13;
  while (cnt[13] < 4) {
    int np = cards[p].back();
    cards[p].pop_back();
    p = np;
    cnt[p]++;
  }
  int ans = 0;
  rep(i, 1, 12) if (cnt[i] == 4) ans++;
  cout << ans;
  return 0;
}